//
//  SearchCell.m
//  TravelDiary
//
//  Created by lanou3g on 15/11/17.
//  Copyright © 2015年 YDB MAC. All rights reserved.
//

#import "SearchCell.h"
#import "LYYSearchCollectionViewCell.h"

@interface SearchCell ()<UICollectionViewDelegateFlowLayout,UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) NSMutableArray *oneArray;
@property (nonatomic, strong) NSMutableArray *twoArray;


@end

@implementation SearchCell

- (void)awakeFromNib {
    self.oneArray = [NSMutableArray arrayWithObjects:@"北京",@"上海",@"海南",@"广州",@"山东", nil];
    self.twoArray = [NSMutableArray arrayWithObjects:@"南锣鼓巷",@"北海公园",@"泰山",@"一线天", nil];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"LYYSearchCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"LYYSearchCollectionViewCell"];
    
    
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (self.flag == 0) {
        return self.oneArray.count;
    }else if (self.flag == 1){
        return self.twoArray.count;
        
    }else{
        return 0;
    }
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"LYYSearchCollectionViewCell";
    LYYSearchCollectionViewCell *cell= [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    if (self.flag == 0) {
        cell.detailLabel.text = self.oneArray[indexPath.row];
    }else if(self.flag == 1){
        cell.detailLabel.text = self.twoArray[indexPath.row];
        
    }
    return cell;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(80, 25);
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(5, 10, 10, 10);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cityName;
    if (self.flag == 0) {
        cityName = self.oneArray[indexPath.row];
        
        NSLog(@"点击了%@",self.oneArray[indexPath.row]);
        
        
    }else if(self.flag == 1){
        cityName = self.twoArray[indexPath.row];
        
        NSLog(@"点击了%@",self.twoArray[indexPath.row]);
        
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"location" object:cityName];
}





- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
